home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / xfcnmscl.sit / XFCN miscellany / stack.txt < prev   
Text File  |  1987-11-22  |  10KB  |  305 lines

  1. -- stack: in
  2. -- format: 8 (HyperCard 1)
  3. -- flags: 0x0 (none)
  4. -- protect password hash: 0
  5. -- maximum user level: 5 (scripting)
  6. -- window: Rect(x1=0, y1=0, x2=0, y2=0)
  7. -- screen: Rect(x1=0, y1=0, x2=0, y2=0)
  8. -- card dimensions: w=0 h=0
  9. -- scroll: x=0 y=0
  10. -- background count: 1
  11. -- first background id: 2690
  12. -- card count: 6
  13. -- first card id: 3016
  14. -- list block id: 5041
  15. -- print block id: 3582
  16. -- font table block id: 0
  17. -- style table block id: 0
  18. -- free block count: 0
  19. -- free size: 0 bytes
  20. -- total size: 20768 bytes
  21. -- stack block size: 8704 bytes
  22. -- created by hypercard version: 0x00000000
  23. -- compacted by hypercard version: 0x00000000
  24. -- modified by hypercard version: 0x00000000
  25. -- opened by hypercard version: 0x00000000
  26. -- patterns[0]: 0x0000000000000000
  27. -- patterns[1]: 0x0000220000002200
  28. -- patterns[2]: 0x8800220088002200
  29. -- patterns[3]: 0xCC003300CC003300
  30. -- patterns[4]: 0xCC883322CC883322
  31. -- patterns[5]: 0xFF00FF00FF00FF00
  32. -- patterns[6]: 0xEECCBB33EECCBB33
  33. -- patterns[7]: 0xFFCCFF33FFCCFF33
  34. -- patterns[8]: 0xFFEEFFBBFFEEFFBB
  35. -- patterns[9]: 0xFFFFFFBBFFFFFFBB
  36. -- patterns[10]: 0x8010022001084004
  37. -- patterns[11]: 0xFFFFFFFFFFFFFFFF
  38. -- patterns[12]: 0x8822882288228822
  39. -- patterns[13]: 0x1122448811224488
  40. -- patterns[14]: 0xC4800C6843023026
  41. -- patterns[15]: 0xB130031BD8C00C8D
  42. -- patterns[16]: 0xAA00AA00AA00AA00
  43. -- patterns[17]: 0x8822552288225522
  44. -- patterns[18]: 0x8855225588552255
  45. -- patterns[19]: 0x77DD77DD77DD77DD
  46. -- patterns[20]: 0x8000000000000000
  47. -- patterns[21]: 0xAA55AA55AA55AA55
  48. -- patterns[22]: 0x5555555555555555
  49. -- patterns[23]: 0x8244394482010101
  50. -- patterns[24]: 0x8814224188412214
  51. -- patterns[25]: 0x8080413E080814E3
  52. -- patterns[26]: 0x22048C7422179810
  53. -- patterns[27]: 0xBE808808EB088880
  54. -- patterns[28]: 0x25C8328964244C92
  55. -- patterns[29]: 0xA29C41BE2AC914EB
  56. -- patterns[30]: 0x40A00000040A0000
  57. -- patterns[31]: 0x8040200002040800
  58. -- patterns[32]: 0xAA00800088008000
  59. -- patterns[33]: 0xFF80808080808080
  60. -- patterns[34]: 0x081C22C180010204
  61. -- patterns[35]: 0xFF808080FF080808
  62. -- patterns[36]: 0xF87422478F172271
  63. -- patterns[37]: 0xBF00BFBFB0B0B0B0
  64. -- patterns[38]: 0xFF7FBE5DA2418000
  65. -- patterns[39]: 0xFAF5FAF5A050A050
  66. -- checksum: 0x0
  67. ----- HyperTalk script -----
  68. on openStack
  69.   hide message box
  70.   pass openStack
  71. end openStack
  72.  
  73. on openCard
  74.   push recent card
  75.   pass openCard
  76. end openCard
  77.  
  78. -- GetFullPath: a function to find the full path name of an application,
  79. -- document or stack. The pathlist is one of 3 globals: applications,
  80. -- documents or stacks- see getHomeInfo in the Home stack's stack script
  81. -- For instance:
  82. --      global stacks
  83. --      put GetFullPath("Browser",stacks) into bpath
  84. -- should compute the full pathname of the Browser stack (if the "Look
  85. -- for stacks in:" card in the Home stack is up to date).
  86.  
  87. function GetFullPath name,pathlist
  88. repeat with i = 1 to the number of lines in pathlist
  89.   if line i of pathlist is empty then next repeat -- sanity check
  90.   put line i of pathlist & name into fname
  91.   if FileModDate(fname,true) is not empty then -- found it
  92.     return fname
  93.   end if
  94. end repeat
  95. return empty   -- file not found in pathlist
  96. end GetFullPath
  97.  
  98. -- NumberOfChars -- utility function that tells you how many times a
  99. -- character turns up in a string
  100. function NumberOfChars theChar, theString
  101. put 0 into charCount
  102. put first character of theChar into theChar -- strip
  103. repeat with i = 1 to the length of theString
  104.   if character i of theString is theChar then add 1 to charCount
  105. end repeat
  106. return charCount
  107. end NumberOfChars
  108.  
  109. -- FileAtRoot: a function that determines if a file is present at
  110. -- the root of a volume (i.e. not buried in a folder somewhere).
  111.  
  112. function FileAtRoot name
  113. put NumberOfChars(":",name) into colonCount
  114. if colonCount is 0 then
  115.   -- No colon in filename, needs expanding before calling this
  116.   -- function!
  117.   return false
  118. end if
  119.  
  120. -- At least 1 colon. If there's more it's not at the root
  121. if colonCount is 1 then
  122.   -- If the file exists, it's at the root.
  123.   if FileModDate(name,true) is not empty then -- empty = file not fnd.
  124.     return true
  125.   else
  126.     return false
  127.   end if
  128. else
  129.   return false
  130. end if
  131. end FileAtRoot
  132.  
  133. -- VolumeName -- given a file pathname, return the name of the volume
  134. -- it resides on. Straightforward string munging.
  135.  
  136. function VolumeName path
  137. put empty into vol
  138. repeat with i = 1 to the length of path
  139.   if character i of path is ":" then -- Stop at first colon
  140.     put ":" after vol
  141.     return vol
  142.   else
  143.     put character i of path after vol
  144.   end if
  145. end repeat
  146.  
  147. -- If we reach here, there's something drastically wrong.
  148. answer "Bad path given to VolumeName" with "OK"
  149. return empty
  150. end VolumeName
  151.  
  152. -- LastPathComponent -- given a file pathname, returns the last
  153. -- component i.e. whatever comes after the last colon, if anything.
  154.  
  155. function LastPathComponent name
  156. -- scan backwards for the last colon.
  157. repeat with i = the length of name down to 1
  158.   if character i of name is ":" then exit repeat
  159. end repeat
  160.  
  161. if i is 1 then
  162.   -- Name was of the form ":thing" or "thing". Check for leading
  163.   -- colon, and adjust if necessary. Done for generality.
  164.   if first character of name is ":" then
  165.     put 2 into i
  166.   end if
  167. else
  168.   add 1 to i -- skip the colon
  169. end if
  170.  
  171. -- Name was of the form "Thing:otherthing". Return "otherThing".
  172. put empty into lastpath
  173. repeat with j = i to the length of name
  174.   put character j of name after lastpath
  175. end repeat
  176. return lastpath
  177. end LastPathComponent
  178.  
  179. -- InvokeApplication : run application in Finder/MultiFinder modes.
  180. -- Will launch or sublaunch. Under MultiFinder, with normal launching,
  181. -- attached documents will only be found if they are at the root of a
  182. -- volume. This script will move documents to the root before issuing
  183. -- the open command. By saving the document's original path in an
  184. -- invisible card field, you can restore it to its original location
  185. -- in a resume handler (not shown in this stack). This problem
  186. -- doesn't happen if you use the sublaunch XFCN.
  187. -- Sublaunching is suppressed (you'd do this if you didn't have enough
  188. -- memory) if the shift key is held down, or true passed as a third
  189. -- parameter.
  190.  
  191. on InvokeApplication progName,docName,noSubLaunch
  192.   global documents
  193.   if MultiFinder() is false then
  194.     if docName is empty then
  195.       open progName
  196.     else
  197.       open docName with progName
  198.     end if
  199.   else
  200.     if IsRunning(progName) is true then
  201.       -- Can't attach a document in this case without invoking
  202.       -- Tempo or QuicKeys. See the ΓÇ£PostEventΓÇ¥ stack for details.
  203.       doMenu progName
  204.     else
  205.       -- Not running. Launch or sublaunch it.
  206.       if the shiftKey is down or noSubLaunch is true then
  207.         -- Override: don't sublaunch, just do a normal launch.
  208.         if docName is not empty then
  209.           -- Need to move the document up to the volume root for this
  210.           -- to work properly due to MultiFinder/Hypercard bug.
  211.           if NumberOfChars(":",docName) is 0 then
  212.             -- Filename needs expanding
  213.             put GetFullPath(docName,documents) into docName
  214.             if docName is empty then
  215.               -- one reason for this would be a previous call that
  216.               -- moved the document up to the root, and the root isn't
  217.               -- on the document search path
  218.               answer "Can't find the document" with "OK"
  219.               exit InvokeApplication
  220.             end if
  221.           end if -- end NumberOfChars
  222.  
  223.           -- Is this document at the root of the volume?
  224.           if FileAtRoot(docName) is false then
  225.             -- Need to move it to the root. Start by computing the
  226.             -- name of the volume.
  227.             put VolumeName(docName) into vol
  228.             if vol is empty then exit InvokeApplication
  229.  
  230.             put MoveFile(docName,vol) into err
  231.             if err is not 0 then
  232.               OsErr err -- report file i/o error
  233.               exit InvokeApplication
  234.             end if
  235.  
  236.             -- Document is now at the root. All we need to do is find
  237.             -- out the new name for the document.
  238.             put vol & LastPathComponent(docName) into docName
  239.           end if -- end FileAtRoot
  240.  
  241.           open docName with progName
  242.         else
  243.           -- No document. Just run the application.
  244.           open progName
  245.         end if -- end docName not empty test
  246.  
  247.         exit InvokeApplication
  248.       end if      -- end shiftKey/override
  249.  
  250.       if docName is empty then
  251.         put SubLaunch(progName) into err
  252.       else
  253.         put SubLaunch(progName,docName) into err
  254.       end if
  255.       if err is not 0 then
  256.         if err < 0 then
  257.           OsErr err
  258.         else if err is 1 then
  259.           -- Parameter error?
  260.           answer "Parameter error in sublaunch call" with "OK"
  261.         else if err is 2 then
  262.           -- System error encountered in sublaunch
  263.           answer "Insufficient memory (or already running?)" with "Failed"
  264.         end if
  265.       end if
  266.     end if
  267.   end if
  268. end InvokeApplication
  269.  
  270. -- OsErr: for displaying Operating system error codes returned by
  271. -- Sublaunch, RenameFile, MoveFile and DeleteFile XFCNs.
  272.  
  273. on OsErr err
  274.   -- Translate the most common ones
  275.   if err > 0 then -- XFCN convention
  276.     put "Parameter error with function" into errstr
  277.   else if err is -59 then
  278.     put "Problem during rename" into errstr
  279.   else if err is -54 then
  280.     put "Attempt to open locked file for writing" into errstr
  281.   else if err is -46 then
  282.     put "Volume locked by software" into errstr
  283.   else if err is -45 then
  284.     put "File locked" into errstr
  285.   else if err is -44 then
  286.     put "Volume locked by hardware" into errstr
  287.   else if err is -43 then
  288.     put "File not found" into errstr
  289.   else if err is -37 then
  290.     put "Bad volume or file name" into errstr
  291.   else if err is -36 then
  292.     put "I/O error" into errstr
  293.   else if err is -35 then
  294.     put "No such volume" into errstr
  295.   else if err is -34 then
  296.     put "Disk is full" into errstr
  297.   else if err is -49 then
  298.     put "File already open for writing" into errstr
  299.   else
  300.     put "Failed with error" && err into errstr
  301.   end if
  302.   answer errstr with "OK"
  303. end OsErr
  304.  
  305.